package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.conf.TimeSetEditVo;
import com.miplus.ccrm.core.controller.vo.conf.TimeSetReqVo;
import com.miplus.ccrm.core.controller.vo.conf.TimeSetResVo;
import com.miplus.ccrm.core.pojo.FiTimeliveSet;
import com.miplus.ccrm.core.mapper.FiTimeliveSetMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author pc
* @description 针对表【FI_TIMELIVE_SET(案件操作时效设置表)】的数据库操作Service实现
* @createDate 2024-12-15 15:35:17
*/
@Service
public class FiTimeliveSetServiceImpl extends MPJBaseServiceImpl<FiTimeliveSetMapper, FiTimeliveSet>
    implements FiTimeliveSetService{

    @Override
    public IPage<TimeSetResVo> timeLiveList(TimeSetReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                TimeSetResVo.class,
                new MPJLambdaWrapper<FiTimeliveSet>()
                        .selectAll(FiTimeliveSet.class)
                        .eq(JPubUtils.IsNotEmpty(paras.getTtype()),TimeSetResVo::getTtype,paras.getTtype())
                        .orderByAsc(TimeSetResVo::getStarttime)
        );
    }

    @Override
    public CmdResVo timeLiveUpdate(String $usrid, TimeSetEditVo paras)
    {
        FiTimeliveSet def=new FiTimeliveSet();
        BeanUtils.copyProperties(paras,def);
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        int ret=baseMapper.updateById(def);
        return new CmdResVo(ret,def.getTid().toString());
    }

    @Override
    public CmdResVo timeLiveInsert(String $usrid,TimeSetEditVo paras)
    {
        FiTimeliveSet def=new FiTimeliveSet();
        BeanUtils.copyProperties(paras,def);
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        int ret=baseMapper.insert(def);
        return new CmdResVo(ret,def.getTid().toString());
    }

    @Override
    public CmdResVo timeLiveDelete(Integer id)
    {
        int ret=baseMapper.deleteById(id);
        return new CmdResVo(ret);
    }
}




